package com.sbl.bajw.pc.service;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sbl.bajw.common.MyBatisDao;
import com.sbl.bajw.common.web.RequestUnit;
import com.sbl.bajw.mapper.DeptPrivilegeModelDao;
import com.sbl.bajw.pc.model.DeptModel;
import com.sbl.bajw.pc.model.DeptPrivilegeModel;

@Service
public class DeptPrivilegeService {
	
	@Resource
	private DeptPrivilegeModelDao dao;
	
	@Resource
	private MyBatisDao gridDao;
	
	public List<HashMap<String, String>> getBusinessType(){
		List<HashMap<String, String>> businessTypes = dao.getBusinessType();
		return businessTypes;
	}
	
	public List<DeptModel> getOrgManagerListAll(){
		String businesstype = RequestUnit.getString("businesstype");
		String userid = RequestUnit.getString("userid");
		HashMap<String, String> parm = new HashMap<String, String>();
		parm.put("businesstype", businesstype);
		parm.put("userid", userid);
		List<DeptModel> models = dao.getOrgManagerList(parm);
		return models;
	}
	
	public void updatePrivilege(){
		String businessType = RequestUnit.getString("businessType");
		String userid = RequestUnit.getString("userid");
		String deptidsStr = RequestUnit.getString("deptids");
		String[] deptids = deptidsStr.split(",");
		
		HashMap<String, String> parm = new HashMap<String, String>();
		parm.put("businesstype", businessType);
		parm.put("userid", userid);
		
		dao.deleteByUser(parm);
		
		for(int i=0;i<deptids.length;i++){
			DeptPrivilegeModel model = new DeptPrivilegeModel();
			model.setBusinessType(businessType);
			model.setUserId(userid);
			model.setDeptId(deptids[i]);
			dao.insert(model);
		}
	}
}
